﻿using System;
using System.Collections.Generic;
using DLM.Infrastructure.Domain;
using System.ComponentModel.DataAnnotations;

namespace DLM.Domain.Model
{
    public class AdminUser : IAggregateRoot, IValidatableObject
    {
        public int AdminID { get; set; }

        [Required(ErrorMessage = "账户不能为空")]
        [RegularExpression(@"[\w\-]{6,15}", ErrorMessage = "昵称允许6-15位数字，字母和下划线")]
        public string Administrator { get; set; }

        [Required(ErrorMessage = "密码不能为空")]
        [RegularExpression(@"^(\S+){6,18}$", ErrorMessage = "密码允许6-18位的字符")]
        public string Password { get; set; }

        public System.DateTime CreateDate { get; set; }

        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            if (string.IsNullOrEmpty(Administrator))
            {
                yield return new ValidationResult("账号不允许为空", new string[] { "AccountName" });
            }
            if (string.IsNullOrEmpty(Password))
            {
                yield return new ValidationResult("密码不允许为空！", new string[] { "Password" });
            }
        }
    }
}
